const FileSystemManeger = wx.getFileSystemManager()
Page({
  data: {
    light:true,
    bkg_color:"white",
    circle:6,
    bg_color:['orange','pink','red','yellow','green','grey'],
    flag : false,
    font_size:30,
    txt:''
  },
  light(){
    if(this.data.light == true){
      this.setData({
        light:!this.data.light,
        bkg_color:"#cccccc"
      })
    }else{
      this.setData({
        light:true,
        bkg_color:"white"
      })
    }
  },
  open_box(e){
    var id = e.currentTarget.dataset.id
    var flag = this.data.flag
    if(flag == false){
      this.setData({
        flag:!this.data.flag,
        num:id
      })
    }else if(flag == true){
      if(this.data.num == id){
        this.setData({
          flag:false
        })
      }else if(this.data.num != id){
        this.setData({
          num:id
        })
      }
    }

  },
  change_zihao(e){
    var id = e.currentTarget.dataset.id
    var font_size = this.data.font_size
    if( id == 1){
      if(font_size > 40){
        wx.showToast({
          title: '已经是最大值了',
        })
      }else{
        font_size += 2
        this.setData({
          font_size :font_size
        })
      }
    }else if(id == 2){
      if(font_size < 20){
        wx.showToast({
          title: '已经是最小值了',
        })
      }else{
        font_size -=2
        this.setData({
          font_size :font_size
        })
      }
    }
  },
  change_bg_color(e){
    var id = e.currentTarget.dataset.id
      this.setData({
        bkg_color:this.data.bg_color[id]
      })
  },
  open_txt(e){
    wx.chooseImage({
      success:res=>{
        var tempFilePath = res.tempFilePaths[0]
        wx.saveFile({
          tempFilePath: tempFilePath,
          success:res=>{
            var savedFilePath = res.savedFilePath
            FileSystemManeger.readFile({
              filePath : savedFilePath,
              // 两种解码，自己看着用
              // encoding:'usc2'
              encoding:'utf-8',
              success:res=>{
                this.setData({
                  txt:res.data
                })
              }
            })
          }
        })
      }
    })

  },
  onLoad(options) {

  },
})